" set a function for end of line
" useful for binary setting
command! -nargs=? -rang=% -bang -complete=file NoEolSave <line1>,<line2>call NOEOLSAVE("<args>", "<bang>")
fun! NOEOLSAVE(filename, bang) range 
    let fline=a:firstline
    let lline=a:lastline
    let filename=a:filename
    let bang=a:bang
    set binary noeol
    try
        if filename == "" && bang == ""
            execute "write"
        elseif filename == "" && bang == "!"
            execute fline.",".lline."write!"
        elseif bang == ""
            execute fline.",".lline."write ".filename
        else
            execute fline.",".lline."write! ".filename
        endif
    catch /E13:/
        echohl ErrorMsg
        echo 'File exist(add ! to override)'
        echohl None
    finally
        set eol nobinary
    endtry
endfunction

